package com.atguigu.gmall.interceptors.interceptors;

import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.user.vo.UserAuthInfoVo;
import com.atguigu.gmall.utils.UserAuthUtils;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
@Slf4j
public class UserHeaderAuthFeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        log.info("进入了拦截器");
        UserAuthInfoVo userAuthInfo = UserAuthUtils.getUserAuthInfo();

        if (!StringUtils.isEmpty(userAuthInfo.getUserId())){
            requestTemplate.header(RedisConst.USER_ID_HEADER,userAuthInfo.getUserId().toString());
        }
        requestTemplate.header(RedisConst.USER_TEMP_ID_HEADER,userAuthInfo.getUserTempId());
        log.info("退出了进入了拦截器");
    }
}
